package com.taotao.job.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 依赖特征：1-可有上下级;2-只可有上级;3-只可有下级;4-不可有上下级
 *
 * @author fanbeibei
 * @date 2021/2/6 22:17
 */
@Getter
@AllArgsConstructor
public enum RelyFeature {

    HAS_PRE_POS(11, "可有上下级"),
    HAS_PRE(10, "只可有上级"),
    HAS_POST(01, "只可有下级"),
    NO_PRE_POST(00, "不可有上下级"),
    ;

    private Integer code;

    private String text;


    private static final Map<Integer, RelyFeature> codeTextMap = new HashMap<>();


    public static boolean mayHasPre(int code) {
        return HAS_PRE_POS.code == code || HAS_PRE.code == code;
    }

    public static boolean mayHasPost(int code) {
        return HAS_PRE_POS.code == code || HAS_POST.code == code;
    }

    static {
        RelyFeature[] values = RelyFeature.values();
        for (RelyFeature val : values) {
            codeTextMap.put(val.code, val);
        }
    }


    public static RelyFeature getByCode(Integer code) {
        return codeTextMap.get(code);
    }

    public static String getTextByCode(Integer code) {
        RelyFeature v = getByCode(code);

        if (null == v) {
            return "未知Code:" + code;
        }
        return v.text;
    }
}
